package com.xj.edu.hotel.controller;

import com.xj.edu.hotel.domain.*;
import com.xj.edu.hotel.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("cityHotel")
public class CityHotelController {
    @Autowired
    private CityService cityService;


   @Autowired
   private HotelService hotelService;
   @Autowired
   private RoomService roomService;

    @Autowired
    private OrderService orderService;
    @Autowired
    private MessageService messageService;

    @RequestMapping("cityhotel")
    @ResponseBody
    public List<City> selectCityHotel() {
        List<City> cityList= cityService.findCityByName();

        return cityList;
    }


    @RequestMapping("hotel")
    @ResponseBody
    public List<Hotel> selectHotel() {
        List<Hotel> hotelList= hotelService.findHotel();
        return hotelList;
    }

    @RequestMapping(value = "/hotelView",method = RequestMethod.GET)
    public  String hotelView(String cityName, Model model){
        //City city = cityService.selectCityByName(cityName);
        List<Hotel> hotelList = hotelService.hotelView(cityName);
        model.addAttribute("hotel",hotelList);
        return "cityHotelView";
    }

    @RequestMapping(value = "/roomView",method = RequestMethod.GET)
    public  String roomView(String hotelName, Model model){
        //City city = cityService.selectCityByName(cityName);
        List<Room> roomList = roomService.roomView(hotelName);
        model.addAttribute("room",roomList);
        return "rooms";
    }

   @RequestMapping("towriteMessage")
   public  String towriteMessage(String id,Model model){
       Order order = orderService.orderitem(id);
       model.addAttribute("order",order);
       return "writeMessage";
   }

   @RequestMapping(value = "/writeMessage",method = RequestMethod.POST)
    public String writeMessage(String userId,String hotelId, String Message){
      Message message = new Message();
      message.setUserId(userId);
      message.setHotelId(hotelId);
      message.setMessage(Message);
      messageService.insertMessage(message);
      return ("redirect:/userOrder/userorder");
   }



}

